package cn.com.jonpad.demo06_simple_project.config;

import cn.com.jonpad.demo06_simple_project.filter.MyFilter;
import cn.com.jonpad.demo06_simple_project.listener.MyListener;
import cn.com.jonpad.demo06_simple_project.servlet.ResourceInitializer;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

@Configuration
public class ServerConfig {
	@Bean
	public ServletRegistrationBean myServlet(){
		ServletRegistrationBean registrat =  new ServletRegistrationBean(new ResourceInitializer(),"/////");
		registrat.setLoadOnStartup(1);
		return registrat;
	}

	@Bean
	public FilterRegistrationBean myFilter(){
		FilterRegistrationBean bean = new FilterRegistrationBean(new MyFilter());
		bean.setUrlPatterns(Arrays.asList("/emps"));
		return bean;
	}

	@Bean
	public ServletListenerRegistrationBean myListener(){
		ServletListenerRegistrationBean bean = new ServletListenerRegistrationBean(new MyListener());
		return bean;
	}
}
